
$(function(){
	if(+defid)infoDefect();

});
var dataHand = new AjaxHandler();
var defid = param.defid;

function infoDefect(){
	$.proAjax({
		url: "/mobile/finddef",
		data: { "defid": defid},
		success: function (data) {
			for(var key in data){
				if($("form").find("#"+key).is("input")){
					if(key=="buildtime" || key=="finishtime"){
						$("form").find("#"+key).val(data[key]==null?"":new Date(data[key]).format("yyyy-MM-dd hh:mm"));
					}else{
						$("form").find("#"+key).val(data[key]);
					}
				}else if($("form").find("#"+key).is("textarea")){
					$("form").find("#"+key).text(data[key]);
				}
			}
			$("#level > span").removeClass("on-active");
			$("#level > span:eq("+data.level+")").addClass("on-active");
			$("#result > span").removeClass("on-active");
			$("#result > span:eq("+data.result+")").addClass("on-active");
				
			}
		})
	};
	function savedef(){
		var level = $("#level .on-active").attr("data-value");
		var result = $("#result .on-active").attr("data-value");
		var pm={
				level:level,
				result:result
			};
		var params = $param(pm); 
		//缺陷描述设置为必填项
        var des = $("#des").val();
        if(des == ""){
        	mui.alert("请填写缺陷描述","提示","确定", function(){
        		$("#des").focus();
        	});
        	return;
        }
        
		$.proAjax({
			url: "/mobile/savedef",
			data: params,
			success: function (data) {
				//history.go(-1);
				//router.href("defectQXD.html",{defid:""});
				/*param.defid="";*/

				mui.back();
			}
		});
	}
	
